package com.hsogoo.avatar.registry;

import org.apache.commons.lang.StringUtils;

import com.hsogoo.avatar.exceptions.AvatarException;
import com.hsogoo.avatar.utils.ConfigUtil;

/**
 * Created by za-huangsaigang on 2018/10/23.
 */
public class RegistryProvider {

    public static AvatarRegistry getRegistry(String registryAddress){
        String defaultRegistryAddress = ConfigUtil.getInstance().getDefaultRegistryAddress();
        String realRegistryAddress = StringUtils.isBlank(registryAddress) ? defaultRegistryAddress : registryAddress;
        if(StringUtils.isBlank(realRegistryAddress)){
            throw new AvatarException(String.format("registry address is empty"));
        }
        AvatarRegistry registry = RegistryLoader.loadDefaultRegistry();
        registry.connectToRegistryServer(realRegistryAddress);
        return registry;
    }
}
